var t = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), e = require("../../../../@babel/runtime/helpers/asyncToGenerator"), n = require("../../../../common/vendor.js"), i = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), r = require("../../../uv-ui-tools/libs/mixin/mixin.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js");

var o = {
    name: "uv-drop-down-popup",
    mixins: [ i.mpMixin, r.mixin ],
    props: {
        sign: {
            type: [ String, Number ],
            default: "UVDROPDOWN"
        },
        zIndex: {
            type: [ Number, String ],
            default: 999
        },
        opacity: {
            type: [ Number, String ],
            default: .5
        },
        clickOverlayOnClose: {
            type: Boolean,
            default: !0
        },
        currentDropItem: {
            type: Object,
            default: function() {
                return {
                    activeIndex: 0,
                    child: []
                };
            }
        },
        keyName: {
            type: String,
            default: "label"
        }
    },
    data: function() {
        return {
            show: !1,
            rect: {},
            height: 0
        };
    },
    computed: {
        overlayStyle: function() {
            var t = this.rect, e = t.height, n = void 0 === e ? 0 : e, i = t.top, r = {
                position: "fixed",
                top: "".concat((void 0 === i ? 0 : i) + n, "px"),
                left: 0,
                right: 0,
                zIndex: this.zIndex,
                bottom: 0,
                "background-color": "rgba(0, 0, 0, ".concat(this.opacity, ")")
            };
            return this.$uv.deepMerge(r, this.$uv.addStyle(this.customStyle));
        },
        list: function() {
            try {
                return Array.isArray(this.currentDropItem.child) ? this.currentDropItem.child : [];
            } catch (t) {
                t = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(t);
                return [];
            }
        },
        getTextColor: function(t) {
            var e = this;
            return function(t) {
                var n = e.currentDropItem.activeIndex == t, i = e.currentDropItem.color, r = e.currentDropItem.activeColor;
                return n ? r || "#3c9cff" : i || "#333";
            };
        },
        getTextSize: function(t) {
            var e = this;
            return function(t) {
                var n = e.currentDropItem.activeIndex == t, i = e.currentDropItem.size, r = e.currentDropItem.activeSize;
                return n ? r || "30rpx" : i || "30rpx";
            };
        },
        itemCustomStyle: function() {
            var t = this;
            return function(e) {
                var n = {};
                return t.currentDropItem.activeIndex == e && t.currentDropItem.itemActiveCustomStyle ? t.$uv.deepMerge(n, t.$uv.addStyle(t.currentDropItem.itemActiveCustomStyle)) : t.currentDropItem.itemCustomStyle ? t.$uv.deepMerge(n, t.$uv.addStyle(t.currentDropItem.itemCustomStyle)) : n;
            };
        }
    },
    created: function() {
        this.init();
    },
    methods: {
        blockClick: function() {},
        clickHandler: function(t, e) {
            this.currentDropItem.activeIndex = e, this.$emit("clickItem", t), this.close();
        },
        init: function() {
            var i = this;
            n.index.$off("".concat(this.sign, "_GETRECT")), n.index.$on("".concat(this.sign, "_GETRECT"), function(t) {
                i.rect = t;
            }), n.index.$off("".concat(this.sign, "_CLICKMENU")), n.index.$on("".concat(this.sign, "_CLICKMENU"), function() {
                var n = e(t().mark(function e(n) {
                    return t().wrap(function(t) {
                        for (;;) switch (t.prev = t.next) {
                          case 0:
                            n.show ? i.open() : i.close();

                          case 1:
                          case "end":
                            return t.stop();
                        }
                    }, e);
                }));
                return function(t) {
                    return n.apply(this, arguments);
                };
            }());
        },
        open: function() {
            var n = this;
            this.show = !0, this.$nextTick(e(t().mark(function e() {
                var i;
                return t().wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return t.next = 2, n.queryRect();

                      case 2:
                        i = t.sent, n.height = i.height, n.$emit("popupChange", {
                            show: !0
                        });

                      case 4:
                      case "end":
                        return t.stop();
                    }
                }, e);
            })));
        },
        close: function() {
            this.show && (this.height = 0, this.height = 0, this.show = !1, n.index.$emit("".concat(this.sign, "_CLOSEPOPUP")), 
            this.$emit("popupChange", {
                show: !1
            }));
        },
        clickOverlay: function() {
            this.clickOverlayOnClose && this.close();
        },
        queryRect: function() {
            var t = this;
            return new Promise(function(e) {
                t.$uvGetRect(".uv-dp__container__list").then(function(t) {
                    e(t);
                });
            });
        },
        animation: function(t) {}
    }
};

Array || (n.resolveComponent("uv-text") + n.resolveComponent("uv-transition"))(), 
Math || (function() {
    return "../../../uv-text/components/uv-text/uv-text.js";
} + function() {
    return "../../../uv-transition/components/uv-transition/uv-transition.js";
})();

var u = n._export_sfc(o, [ [ "render", function(t, e, i, r, o, u) {
    return {
        a: n.f(u.list, function(t, e, r) {
            return {
                a: "6046ae38-1-" + r + ",6046ae38-0",
                b: n.p({
                    text: t[i.keyName],
                    size: u.getTextSize(e),
                    color: u.getTextColor(e)
                }),
                c: e,
                d: n.o(function(n) {
                    return u.clickHandler(t, e);
                }, e),
                e: n.s(u.itemCustomStyle(e))
            };
        }),
        b: "".concat(o.height, "px"),
        c: n.o(function() {
            return u.blockClick && u.blockClick.apply(u, arguments);
        }),
        d: n.o(u.clickOverlay),
        e: n.p({
            show: o.show,
            mode: "fade",
            duration: 300,
            "custom-style": u.overlayStyle
        })
    };
} ], [ "__scopeId", "data-v-6046ae38" ] ]);

wx.createComponent(u);